package com.example.vae.Adapter;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.vae.R;

import java.util.List;

//这个是初始化 粉丝查找页面的dadapter
public class InforItemRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private LayoutInflater layoutInflater;
    private List<Integer> imageviews;
    private List<String> names;
    private List<Integer> sexs;


    public InforItemRecyclerViewAdapter(Context context){
        this.context = context;
    }

    public InforItemRecyclerViewAdapter(Context context, List<Integer> imageviews, List<String> names,List<Integer> sexs){
        this.context=context;
        this.imageviews=imageviews;
        this.names=names;
        this.sexs=sexs;
        layoutInflater=LayoutInflater.from(context);
    }

    //    初始化item布局
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

       View view=layoutInflater.inflate(R.layout.info_item,parent,false);
        DisplayMetrics dm=context.getResources().getDisplayMetrics();
        int height=dm.heightPixels;
        view.getLayoutParams().height=height/10;
        MyViewHolder myViewHolder=new MyViewHolder(view);
        return myViewHolder;
    }

    //    处理每一个item 的地方,绑定数据
    @Override
    public void onBindViewHolder( RecyclerView.ViewHolder holder, int position) {

        MyViewHolder myViewHolder=(MyViewHolder)holder;
        myViewHolder.iv.setImageResource(imageviews.get(position));
        myViewHolder.name.setText(names.get(position));
        myViewHolder.sex.setImageResource(sexs.get(position));

    }

    //    显示数量，因为我的布局文件就是三个，所以我返回san
    @Override
    public int getItemCount() {
        return imageviews.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{

        private ImageView iv;
        private ImageView sex;
        private ImageView xiaoguo;
        private TextView name;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
           iv=itemView.findViewById(R.id.iv);
           sex=itemView.findViewById(R.id.sex);
            xiaoguo=itemView.findViewById(R.id.xiaoguo);
            name=itemView.findViewById(R.id.name);
        }
    }

}